/**
INFO:
	to get the Background from some picture
Author:
	Mark on 2014/4/10
	<mark199312@gmail.com>
*/

#include"PGerneralHead.h"
#include"Thread.h"

#ifndef BACKGROUND_H
#define BACKGROUND_H

static int BMTNUM=10;
static int BAMARGINERROR=40;

class Background : public Thread
{
protected:
	

public:
	Mat bM;
	vector<Mat> bMT;
	bool **bMB;


	Background();
	~Background();
	Mat getBM();

	bool ** getBMB()
	{
		return this->bMB;
	}

	void setBM(Mat bM);
	void initbMB();

	void addBMT(Mat bMT);

	void display();

	void updata();
	


	/**
	what we think is to init the background as the first bMT;
	and to compare to the other picture to get the speicific background
	finally to average the all bMT as the unsure pixel
	*/

	bool inMarginOfError(int a,int b,int marginError=BAMARGINERROR);

	void getSameAverage(Mat m,Mat n);

	void getBackFromBMT();

	int countBMB();

	void cutBackground();


	/**
	next is to process the Background to denoising
	*/

	void denoising(int N,int M);

	void save(Mat m)
	{
		imwrite("background.bmp",m);
	}

	/*
	MatND getHisttogram(Mat &Image)
	{
		MatND hist;

		calcHist(1,Image.channels(),Mat(),hist,1,Image);

	}
*/

	void run();
};

#endif